package com.bybops.utils;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Environment;
import android.provider.Settings;
import android.support.v4.app.ActivityCompat;
import android.telephony.TelephonyManager;

import com.bybops.app.MyApplication;

public class DeviceInfoUtil {

    public static final String ANDROID_OS_VERSION_RELEASE = "Android_" + android.os.Build.VERSION.RELEASE;

    /* 获取手机型号 */
    public static String getModel() {
        return android.os.Build.MODEL;
    }

    /* 获取操作系统版本号 */
    public static String getOsVersion() {
        return android.os.Build.VERSION.RELEASE;
    }

    /* 获取手机唯一序列号 */
    public static String getDeviceId() {
        String android_id = Settings.Secure.getString(MyApplication.Companion.getInstance().getContentResolver(),
                Settings.Secure.ANDROID_ID);
        TelephonyManager tm = (TelephonyManager) MyApplication.Companion.getInstance()
                .getSystemService(MyApplication.Companion.getInstance().TELEPHONY_SERVICE);
        if (ActivityCompat.checkSelfPermission(MyApplication.Companion.getInstance(), Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
            return "";
        } else {
            //有权限
            String str = tm.getDeviceId() + android_id;
            // 进行MD5加密
            return Md5Util.encrypt(str);

        }
    }

    /**
     * 是否有SD卡
     * @return
     */
    public static boolean hasSDCard(){
        String state= Environment.getExternalStorageState();
        if(state.equals(Environment.MEDIA_MOUNTED))
            return true;
        return false;
    }


}
